package com.czx.user.domain.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.czx.core.web.domain.entities.IpInfo;
import lombok.*;

import java.util.Date;

@Data
@EqualsAndHashCode(callSuper = false)
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "user", autoResultMap = true)
public class User {

    public static Long UID_SYSTEM = 1L;//系统uid
    private static final long serialVersionUID = 1L;

    /**
     * 用户id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 用户昵称
     */
    @TableField("name")
    private String name;

    /**
     * 用户头像
     */
    @TableField("avatar")
    private String avatar;

    /**
     * 性别 1为男性，2为女性
     */
    @TableField("sex")
    private Integer sex;

    /**
     * 手机号
     */
    @TableField("phone_number")
    private String phoneNumber;
    /**
     * 介绍
     */
    @TableField("introduction")
    private String introduction;

    /**
     * 地址
     */
    @TableField("address")
    private String address;

    /**
     * 微信openid用户标识
     */
    @TableField("open_id")
    private String openId;

    /**
     * 上下线状态 1在线 2离线
     */
    @TableField("active_status")
    private Integer activeStatus;

    /**
     * 最后上下线时间
     */
    @TableField("last_opt_time")
    private Date lastOptTime;

    /**
     * 最后上下线时间
     */
    @TableField(value = "ip_info", typeHandler = JacksonTypeHandler.class)
    private IpInfo ipInfo;

    /**
     * 用户状态 0正常 1拉黑
     */
    @TableField("status")
    private Integer status;

    /**
     * 被关注数量（粉丝数)
     */
    @TableField("followed_num")
    private Long followed;

    /**
     * 关注数
     */
    @TableField("follow_num")
    private Long follow;

    @TableField(value = "created_by")
    private Long createdBy;

    @TableField(value = "created_time")
    private Long createdTime;

    @TableField(value = "created_name")
    private String createdName;

    @TableField(value = "updated_by")
    private Long updatedBy;

    @TableField(value = "updated_time")
    private Long updatedTime;

    @TableField(value = "updated_name")
    private String updatedName;

    @TableField("del_flag")
    @TableLogic(delval = "id")
    private Integer delFlag;

    public void refreshIp(String ip) {
        if (ipInfo == null) {
            ipInfo = new IpInfo();
        }
        ipInfo.refreshIp(ip);
    }


}